<template>
	<view class="page-wrap u-skeleton">
		<view>
			<form ref="fd" @submit="formSubmit" @reset="formReset" >
				<view style="display: inline;">
					<view class="uni-form-item uni-column form_row_btn">
						<image src="/static/icon/ss.png" class="formimg" @tap="search"  ></image>
						<image src="/static/icon/sx.png" class="formimg" @tap="reset"  ></image>
						<uni-icons type="plusempty" size="18px" @tap="add" style="color: white;"></uni-icons>
					</view>
					<!-- <view class="uni-form-item uni-column form_row">
						<label class="form_row_lable">牌号:</label>
						<input name="ph" class="form_row_input" placeholder="请输入..." />
					</view> -->

				</view>
			</form>
		</view>
		
		<data-list class="data-list data_list_fomatter" @load="handleLoad" @refresh="handleRefresh">
			<view class="item_box" v-for="(item, index) in list" :key="index">
				<view class="item_box_box">
					<text  class="item_box_box_text" >
						<image src="/static/icon/bj.png" class="table_img" @tap="edit(item)"  ></image>
						<image src="/static/icon/sc.png" class="table_img2" @tap="del(item.id)"></image>
					</text>
					<view class="item_box_box_text_view"></view>
					<text class="table_lable">牌号:</text> <text class="table_val">{{item.ph}}\n</text>
					<text class="table_lable">*包内铁水成分标准硅%:</text> <text class="table_val">{{item.cuBz}}\n</text>
					<!-- <text class="table_lable">电炉铁水成分标准锡%:</text> <text class="table_val">{{item.snBz}}\n</text> -->
					<text class="table_lable">*包内铁水成分标准锰%:</text> <text class="table_val">{{item.mnBz}}\n</text>
					<text class="table_lable">硅粒硅含量%:</text> <text class="table_val">{{item.tlCuhl}}\n</text>
					<text class="table_lable">硅粒硅吸收率%:</text> <text class="table_val">{{item.tlCuxsl}}\n</text>
					<!-- <text class="table_lable">锡粒锡含量%:</text> <text class="table_val">{{item.xlSnhl}}\n</text>
					<text class="table_lable">锡粒锡吸收率%:</text> <text class="table_val">{{item.xlSnxsl}}\n</text>
					 --><text class="table_lable">锰铁含锰量%:</text> <text class="table_val">{{item.mtMnhl}}\n</text>
					<text class="table_lable">锰铁锰吸收率%:</text> <text class="table_val">{{item.mtMnxsl}}\n</text>
				</view>
			</view>
		</data-list>
		
	</view>
</template>

<script>
	import configService from '@/common/config.service.js';
	const apiUrl = configService.apiUrl;
export default {
	data() {
		return {
			list: [],//分页数据 this.list
			total: 0,//总条数
			totalNum: 2,//总页数
			
			num_plus : true,//页数是否增加
			formParam:{},
			model : {// 页面模型对象 
			},
			param : {      //传递的page参数
				page : 1,//页码
				size : 10,//每页条数,
				deptId:uni.getStorageSync("deptId"),
				type: 3
			}
		};
	},
	computed: {
	// onShow:function(e){
	// 	this.$verify.verify();
	// 	this.dws = this.$dict.dwsDist();
	// 	this.dwsDistObj =  this.$dict.dwsDistObj();
	// 	let user = uni.getStorageSync("user");
	// 	this.model.dw = user.deptId;
	// 	this.model.factoryName = this.dws[this.model.dw - 1];
		
	// 	this.user = user;
	},

	methods: {
		search(){			console.log(this.$refs.fd);			this.$refs.fd._onSubmit()			// console.log(this.$refs.targetBtn);		},		formSubmit(e) {  			console.log(e) // 获取原生的 input 事件对			this.list =[];			this.formParam =  e.detail.value;			this.to_Ajax({ ...this.param,...this.model,...this.formParam});//合并三个参数对象并传递		},		formReset(){			this.param.page = 1;			this.list = [];			this.to_Ajax({ ...this.param,...this.model});			},//合并三个参数对象并传递		reset(){			console.log(this.$refs.fd);			this.$refs.fd._onReset()			// console.log(this.$refs.targetBtn);		},		del(id){
			let _this = this;
				uni.showModal({
					title: '提示',
					content: "确定删除吗?",
					success: function (res) {
						if (res.confirm) {
							console.log('用户点击确定');
							uni.showLoading();
							uni.request({
								url: apiUrl + '/bnhjcftzss/remove', 
								data : {id : id},
								header: {
									 'Content-Type': 'application/json' //自定义请求头信息
								},
								method:'POST',//请求方式，必须为大写
								success: (res) => {
									let msg = res.data.msg;
									if(res.data.code == 200){
										uni.showModal({
											title: '提示',
											content: msg,
											success: function (res) {
												if (res.confirm) {
													console.log('用户点击确定');
													_this.$common.showToast(msg);
													_this.handleRefresh();
												} else if (res.cancel) {
													console.log('用户点击取消');
												}
												
											}
										});
										uni.hideLoading();
									}else{
										uni.showToast({
											title: title,
											icon:'erro',
											duration:2500
										});
									}
								}
							 })
							 } else if (res.cancel) {
								console.log('用户点击取消');
								return;
								}
						},
			})							
			
		},
		add(){
			this.$common.navigateTo("/pages/灰铁/bzwh/bnhjcftzAdd");
		},
		edit(item){
			this.$common.navigateTo("/pages/灰铁/bzwh/bnhjcftzEdit?item=" 
			+ encodeURIComponent(JSON.stringify(item)));
		},
		// 模拟请求加载数据
		handleLoad(data, callback) {
			if(this.totalNum > this.param.page){
				this.to_Ajax({...this.param, ...this.formParam,...this.model},data, callback);
			}
		},
		// 模拟请求数据刷新
		handleRefresh(data, callback) {
			this.param.page = 1;
			this.list = [];
			this.to_Ajax({...this.param, ...this.formParam,...this.model},data, callback);
		},
		to_Ajax(param,data, callback){
			uni.showLoading({
			      title: '加载中...'
			});
			let list = [];
			let total = 0;
			let totalNum = 0;//总页数
			uni.request({
				url: apiUrl + '/bnhjcftzss/list', 
				data : param,
				header: {
					 'Content-Type': 'application/json' //自定义请求头信息
				},
				method:'POST',//请求方式，必须为大写
				success: (res) => {
					let re = res.data;
					if(re.code == 200){
						list = re.data.rows;
						total = re.data.total;
						totalNum = Math.ceil(re.data.total / this.param.size);//向上取整
						this.totalNum = totalNum;
					}
					this.list = [...this.list, ...list];
					if(callback){
						callback({ list: this.list, total: this.total,
						param:{
							page : this.param.page, size : this.param.size
						}});
					}
					//页码++
					if(this.totalNum > this.param.page){
						this.param.page ++  ; 
					}
					 uni.hideLoading();
				}
			 })
		}
	}
};
</script>

<style scoped lang="scss">
	@import "@/common/commonFonmatter.css";
</style>
